import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName WordCount
 * @Deacription TODO
 * @Author wushumin
 * @Date 2021-06-21 16:01
 * @Version 1.0
 **/
public class WordCount {
    public static void main(String[] args) {
        final StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
        List<Person> data = new ArrayList<>();
//        DataStream<Person> dataStream = environment.fromElements(
//                new Person("Fred", 35),
//                new Person("lisi", 20),
//                new Person("wangwu", 15)
//        );
        data.add( new Person("Fred", 35));
        data.add(new Person("lisi", 20));
        data.add(new Person("wangwu", 15));
        DataStreamSource<Person> dataStream = environment.fromCollection(data);
        DataStreamSink<Person> streamSink = dataStream.filter(person -> person.age >= 18)
                .print();

        try {
            environment.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static class Person implements Serializable {
        private final int age;
        private final String name;

        public Person(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        public String getName() {
            return name;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "age=" + age +
                    ", name='" + name + '\'' +
                    '}';
        }
    }
}
